<template>
	<view>
		<view class="goods-item">
			<view class="goods-item-left">
				<radio v-if="showRadio" @click="radioHandler" :checked="goods.goods_state" :color="'red'"></radio>
				<image class="good-pic" :src="getHttpsImage(goods.goodsSmallLogo) ||defultpic"></image>
			</view>
			<view class="goods-item-right">
				<view class="goods-name">
					{{goods.goodsName}}
				</view>
				<view class="good-info-box">
					<view class="good-price">
						{{FixPrice(goods.goodsPrice)}}￥
					</view>
					<uni-number-box @change="numberHandler" v-if="showNum" :value="goods.goods_count" :min="1"></uni-number-box>
				</view>
			</view>
		</view>

	</view>
</template>
		
<script>
	export default {
		name:"goods",
		props: {
			showNum:{
				type:Boolean,
				default:false
			},
			showRadio:{
				type:Boolean,
				default:false
			},
			goods: {
				type: Object,
				default: {}
			}
		},
		methods:{
			numberHandler(e){
				console.log(e)
				this.$emit('number-change',{
					goods_count : e,
					goodsId:this.goods.goodsId
				})
			},
			radioHandler(){
				this.$emit('radio-change',{
					goodsId:this.goods.goodsId,
					goods_state:this.goods.goods_state
				})
			},
			FixPrice(price){
				return Number(price).toFixed(2)
			},
			getHttpsImage(url) {
			  return url.replace(/^http:/, 'https:');
			}
		},
		data() {
			return {				
				defultpic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'			
			};
		}	
	}
</script>
<style lang="scss">
	.goods-item {
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid #efefef;
		
		.goods-item-left {
			margin-right: 5px;
			display: flex;
			
			align-items: center;
			.good-pic {
				height: 100px;
				width: 100px;
				display: block;
			}
		}

		.goods-item-right {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			.goods-name{
				font-size: 12px;
			}
			.good-price {
				color: red;
				font-size: 15px;
			}
			.good-info-box{
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}
	}
</style>